package edu.ustb.service.xiumi.impl;

import edu.ustb.domain.user.Users;
import edu.ustb.mapper.user.UsersDao;
import edu.ustb.service.xiumi.xiumiInputControllerService;
import edu.ustb.utils.MybatisUtil;

import java.util.List;

public class xiumiInputControllerServiceImpl implements xiumiInputControllerService {
    @Override
    public boolean ifChangedPass(String info, String passOld, String passNew) {

        System.out.println(info + "  " + passOld + "  " + passNew);
        UsersDao mapper =
                MybatisUtil.getMapper(edu.ustb.mapper.user.UsersDao.class);
        Users users = mapper.findByPhoneNum(info);
        // 判断初始密码是否正确
        if(users.getUserPass().equals(passOld)){
            System.out.println("初始密码正确");
            int rows =
                    mapper.updateById(users.getUserId(), passNew);
            if(rows > 0){
                System.out.println((mapper.findByPhoneNum(info).toString()));
                List<Users> all = mapper.findAll();
                for(Users u:all){
                    System.out.println(u.toString());
                }
                MybatisUtil.close();
                return true;
            }else{
                System.out.println("意外错误 自建");
                MybatisUtil.close();
                System.out.println((mapper.findByPhoneNum(info).getUserPass()));
                return false;
            }
        }else{
            MybatisUtil.close();
            return false;
        }
    }
}
